package com.wswy.wzcx.ui.user

import android.content.Context
import android.support.v4.content.ContextCompat
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.TextPaint
import android.text.style.ClickableSpan
import android.text.style.ForegroundColorSpan
import android.view.View
import com.wswy.wzcx.R
import com.wswy.wzcx.api.ConfigsKt
import com.wswy.wzcx.model.home.RouterUtils

object LoginHelper {


    fun getServiceString(context:Context):CharSequence = SpannableStringBuilder().apply {
        append("我已阅读并同意")
        append(SpannableString("《用户服务协议》").apply {
            setSpan(ForegroundColorSpan(ContextCompat.getColor(context,R.color.colorPrimary)),0,length, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
            setSpan(object : ClickableSpan(){
                override fun onClick(widget: View) {

                    RouterUtils.startWeb(widget.context, ConfigsKt.H5_TERMS_OF_SERVICE)
                }
                override fun updateDrawState(ds: TextPaint) {
                    super.updateDrawState(ds)
                    ds.isUnderlineText = false
                    ds.color = ContextCompat.getColor(context,R.color.colorPrimary)
                    ds.clearShadowLayer()
                }
            },0,length, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
        })
        append("及")
        append(SpannableString("《隐私政策》").apply {
            setSpan(ForegroundColorSpan(ContextCompat.getColor(context,R.color.colorPrimary)),0,length, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
            setSpan(object : ClickableSpan(){
                override fun onClick(widget: View) {

                    RouterUtils.startWeb(widget.context, ConfigsKt.H5_PRIVACY_POLICY)
                }
                override fun updateDrawState(ds: TextPaint) {
                    super.updateDrawState(ds)
                    ds.isUnderlineText = false
                    ds.color = ContextCompat.getColor(context,R.color.colorPrimary)
                    ds.clearShadowLayer()
                }
            },0,length, SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
        })
    }

}